import { Menu, nativeImage, Tray,app } from "electron";
import { join } from "node:path";
import { clear,focus } from "./main";
let tray: Tray | null = null
/**
 * 创建系统托盘
 */
export const createTray = () => {
  const img = nativeImage.createFromPath(join(process.env.VITE_PUBLIC, 'tray.png'))
  tray = new Tray(img)
  tray.setTitle("electron-vue-next")
  tray.setToolTip("electron-vue-next")

  const menu = Menu.buildFromTemplate([{
    id: '1',
    label: '打开主界面',
    click:focus
  }, {
    id: '9',
    label: '退出',
    click:()=>{
      clear()
      app.quit()
    }
  }])


  tray.setContextMenu(menu)
  //双击打开主界面
  tray.on("double-click", async () => {
    await focus()
  })
}